<!--完成-->

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>班级管理</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/class-manage.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#0CB07B',
                        neutral: '#F5F7FA',
                        dark: '#1D2129',
                        light: '#FFFFFF'
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .card-shadow {
                box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            }
            .btn-hover {
                transition: all 0.3s ease;
            }
            .btn-hover:hover {
                transform: translateY(-2px);
                box-shadow: 0 4px 12px rgba(22, 93, 255, 0.2);
            }
            body {
            background-image: url('/images/background.jpg'); /* 假设图片放在public/images目录下 */
            background-size: cover;
            background-position: center;
            background-attachment: fixed;
            background-repeat: no-repeat;
            z-index: -1;  /* 确保低于内容层级 */
        }

            body::before {
                display:none;
            }
        }
        /* 模态框基础样式 */
    .modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    .modal.active {
        opacity: 1;
        visibility: visible;
        display: flex;
    }
    
    .modal-content {
        background: white;
        border-radius: 12px;
        box-shadow: 0 12px 36px rgba(0, 0, 0, 0.2);
        width: 90%;
        max-width: 600px;
        max-height: 90vh;
        overflow-y: auto;
        transform: translateY(20px);
        transition: all 0.3s ease;
    }
    
    
    .modal.active .modal-content {
        transform: translateY(0);
    }
    
    .modal-header {
        padding: 20px;
        border-bottom: 1px solid #eee;
        position: relative;
    }
    
    .modal-title {
        font-size: 1.25rem;
        font-weight: 600;
        color: #2c3e50;
        margin: 0;
    }
    
    .close {
        position: absolute;
        top: 20px;
        right: 20px;
        font-size: 1.5rem;
        color: #7f8c8d;
        cursor: pointer;
        background: none;
        border: none;
    }
    
    .close:hover {
        color: #2c3e50;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 20px;
        border-top: 1px solid #eee;
        display: flex;
        justify-content: flex-end;
        gap: 10px;
        flex-shrink: 0;
    }
    /* 添加下拉菜单样式 */
    #user-dropdown{
        border: 1px solid #e5e7eb;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    #user-dropdown a:hover{
        background-color: #f9fafb;
    }
    </style>
</head>
<body class="bg-neutral font-inter text-dark">
    <header class="bg-primary text-white shadow-sm sticky top-0 z-50">
        <div class="container mx-auto px-4 py-3 flex justify-between items-center">
            <div class="flex items-center space-x-2">
                <i class="fa-solid fa-book-open text-white text-2xl"></i>
                <h1 class="text-xl font-bold text-white">班级管理</h1>
            </div>
            <nav>
                <ul class="flex space-x-6 items-center">
                    <li><a href="#" class="text-white hover:text-neutral-200 transition-colors duration-300">返回</a></li>
                </ul>
            </nav>
            <div class="flex items-center space-x-3">
                <!-- 修改开始：添加用户信息容器 -->
                <div id="user-info-container" class="hidden text-right mr-2">
                    <div id="user-name" class="font-medium text-white"></div>
                    <div id="student-id" class="text-xs text-white/80"></div>
                </div>
                <!-- 头像区域（添加下拉菜单） -->
                <div class="relative">
                    <a href="#" id="user-avatar" class="text-white hover:text-neutral-200 transition-colors duration-300">
                        <i class="fa-solid fa-user-circle text-xl"></i>
                    </a>
                    <!-- 下拉菜单 -->
                    <div id="user-dropdown" class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg py-1 z-50 hidden">
                        <a href="#" onclick="editProfile()" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
                            <i class="fas fa-user-edit mr-2"></i>编辑个人资料
                        </a>
                        <a href="#" onclick="logout()" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
                            <i class="fas fa-sign-out-alt mr-2"></i>退出登录
                        </a>
                    </div>
                </div>
            </div>
    </header>
    <main class="container mx-auto px-4 py-8">
        <div class="flex justify-between items-center mb-6">
            <h1 class="text-2xl text-white font-bold">班级管理</h1>
            <button onclick="createClass()" class="bg-primary hover:bg-blue-700 text-white px-4 py-2 rounded-lg btn-hover flex items-center space-x-2">
                <i class="fa-solid fa-plus mr-2"></i>创建班级
            </button>
            <button onclick="goBack()" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-lg btn-hover">
                <i class="fa-solid fa-arrow-left mr-2"></i>返回
            </button>
        </div>
        <!-- 在班级列表上方添加操作引导 -->
<div class="bg-blue-50 border-l-4 border-primary p-4 mb-6 rounded">
    <div class="flex items-start">
        <div class="flex-shrink-0">
            <i class="fa-solid fa-lightbulb text-primary text-xl"></i>
        </div>
        <div class="ml-3">
            <p class="text-sm text-gray-700">
                点击班级卡片查看成员，也可以在主页面或通过本页面中间的创建班级按钮创建新的班级。
            </p>
        </div>
    </div>
</div>
        <div id="classList" class="bg-gradient-to-r from-blue-200/80 to-indigo-50/80 rounded-lg shadow-md p-6 mb-6 backdrop-blur-sm">
            <div class="flex justify-between items-center mb-6">
                <h2 class="text-xl font-semibold">我的班级</h2>
            </div>
            <div id="classesContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                <!-- 班级卡片将通过JS动态加载 -->
            </div>
        </div>
        
        <!-- 班级成员模态框 -->
        <div id="classMembersModal" class="modal fixed inset-0 z-50 hidden">
            <div class="modal-overlay absolute inset-0 bg-black opacity-50"></div>
            <div class="modal-content bg-white rounded-lg card-shadow p-6 max-w-4xl w-full relative mx-auto my-12">
                <span class="close absolute top-4 right-4 text-2xl cursor-pointer hover:text-gray-600" onclick="closeClassMembersModal()">&times;</span>
                <h2 id="classNameHeader" class="text-xl font-semibold mb-4">班级成员</h2>
                <div class="overflow-x-auto">
                    <table id="classMembersTable" class="w-full border-collapse">
                        <thead>
                            <tr class="bg-gray-100">
                                <th class="p-3 text-left">学号</th>
                                <th class="p-3 text-left">姓名</th>
                                <th class="p-3 text-center">练习进度</th>
                                <th class="p-3 text-center">操作</th>
                            </tr>
                        </thead>
                        <tbody id="classMembersBody" class="divide-y divide-gray-200">
                            <!-- 成员数据将通过JS动态填充 -->
                        </tbody>
                    </table>
                </div>
                <div class="flex justify-end mt-6">
                    <button onclick="closeClassMembersModal()" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-lg btn-hover">
                        关闭
                    </button>
                </div>
            </div>
        </div>
        <!-- 创建班级模态框 -->
    <div id="createClassModal" class="fixed inset-0 z-50 flex items-center justify-center hidden">
        <div class="absolute inset-0 bg-black/50"></div>
        <div class="relative bg-white rounded-lg shadow-lg max-w-2xl w-full mx-auto p-6 max-h-[90vh] overflow-y-auto">
            <div class="flex justify-between items-center mb-4 sticky top-0 bg-white z-10 py-2">
                <h2 class="text-xl font-semibold text-dark">创建班级</h2>
                <button class="close text-2xl absolute top-4 right-6" onclick="closeCreateClassModal()">&times;</button>
            </div>
            <form class="grid grid-cols-1 gap-4">
                <div class="mb-4">
                    <label for="classCode" class="block text-sm font-medium text-gray-dark mb-1">班级编号：</label>
                    <input type="text" id="classCode" placeholder="不能为空" class="form-input">
                </div>
                <div class="mb-4">
                    <label for="className" class="block text-sm font-medium text-gray-dark mb-1">班级名称：</label>
                    <input type="text" id="className" placeholder="不能为空" class="form-input">
                </div>
                <input type="hidden" id="classCreatorId">
                <div class="flex justify-end space-x-3 mt-6">
                    <button type="button" onclick="closeCreateClassModal()" class="px-4 py-2 border border-gray-medium rounded-md text-gray-dark hover:bg-gray-light transition-colors">取消</button>
                    <button type="button" onclick="saveClass()" class="px-4 py-2 bg-primary text-white rounded-md hover:bg-primary/90 transition-colors">保存</button>
                </div>
            </form>
        </div>
    </div>

        <!-- 导入成员名单模态框 -->
        <div id="importMembersModal" class="modal fixed inset-0 z-50 hidden">
            <div class="modal-overlay absolute inset-0 bg-black opacity-50"></div>
            <div class="modal-content bg-white rounded-lg card-shadow p-6 max-w-2xl w-full relative mx-auto my-12">
                <span class="close absolute top-4 right-4 text-2xl cursor-pointer hover:text-gray-600" onclick="closeImportMembersModal()">&times;</span>
                <h2 class="text-xl font-semibold mb-4">导入成员名单</h2>
                <div class="bg-gray-50 p-4 rounded-lg mb-4">
                    <h4 class="font-medium mb-2">导入步骤：</h4>
                    <ol class="list-decimal list-inside space-y-1 text-sm text-gray-600">
                        <li>准备符合格式要求的Excel文件</li>
                        <li>点击"选择文件"按钮上传</li>
                        <li>确认无误后点击"导入"按钮</li>
                        <li>等待导入完成查看结果</li>
                    </ol>
                </div>
                <p class="mb-4 text-gray-600">请上传.xlsx格式的文件，文件中需包含学号和姓名信息</p>
                <input type="hidden" id="importClassCode">
                <div class="mb-4">
                    <label class="block text-gray-700 mb-2">选择文件</label>
                    <input type="file" id="importFile" accept=".xlsx" class="w-full p-2 border border-gray-300 rounded">
                </div>
                <div class="flex justify-between mt-6">
                    <button onclick="openImportHelpModal()" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-lg btn-hover">
                        <i class="fa-solid fa-question-circle mr-2"></i>查看导入帮助
                    </button>
                    <div class="space-x-3">
                        <button onclick="closeImportMembersModal()" class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2 rounded-lg btn-hover">
                            取消
                        </button>
                        <button onclick="importMembers()" class="bg-primary hover:bg-blue-700 text-white px-4 py-2 rounded-lg btn-hover">
                            <i class="fa-solid fa-upload mr-2"></i>导入
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 导入帮助模态框 -->
        <div id="importHelpModal" class="modal fixed inset-0 z-50 hidden">
            <div class="modal-overlay absolute inset-0 bg-black opacity-50"></div>
            <div class="modal-content bg-white rounded-lg card-shadow p-6 max-w-4xl w-full relative mx-auto my-12 max-h-[90vh] overflow-y-auto">
                <span class="close absolute top-4 right-4 text-2xl cursor-pointer hover:text-gray-600" onclick="closeImportHelpModal()">&times;</span>
                <h2 class="text-xl font-semibold mb-4">导入帮助</h2>
                <div class="prose max-w-none">
                    <p class="mb-3">这个帮助将会引导您选择合适的名单进行导入，以满足批量导入班级成员的需求，首先，你选择的文件必须为.xlsx的格式。</p>
                    <p class="mb-3">平台进行导入时只考虑这个文件中第一个表格的内容(即下图中sheet1表格)</p>
                    <div class="mb-4 flex justify-center">
                        <img src="images/import_help.png" alt="导入示例图片" class="max-w-full h-auto border border-gray-200 rounded">
                    </div>
                    <p class="mb-3">选择文件中这个表格的表头(即A1、B1单元格)必须为学号和姓名，否则会导入失败</p>
                    <p class="mb-3">从第二行开始，A列所在单元格被视为要导入学生的学号，B列单元格被视为要导入学生的姓名</p>
                    <p class="mb-3">只有当学号和姓名都与某个存在的学生匹配时，导入才会成功</p>
                    <p class="mb-3">否则，导入失败，但是导入流程不会因此终止，会直接检查下一行的学生信息进行导入，直到导入结束</p>
                    <p class="mb-3">因为导入的学生可能很多，所以在某一行导入失败时不会单独给出提示，但我们会在导入结束后给出导入成功的学生数</p>
                    <p class="mb-6">所以，您可以根据导入成功的学生数检查导入情况，也可以在导入结束后查看成员名单</p>
                    <div class="flex justify-end">
                        <button onclick="closeImportHelpModal()" class="bg-primary hover:bg-blue-700 text-white px-4 py-2 rounded-lg btn-hover">
                            返回
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <footer class="bg-dark text-white py-8 mt-12">
        <div class="container mx-auto px-4">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
                <div>
                    <h3 class="text-lg font-semibold mb-4">班级管理</h3>
                    <p class="text-gray-400">您可以在此页面管理您的班级成员，并查看他们的学习进度。</p>
                </div>
                <div>
                    <h3 class="text-lg font-semibold mb-4">联系我们</h3>
                    <ul class="space-y-2 text-gray-400">
                        <li><i class="fa-solid fa-envelope mr-2"></i> softclass-platform@qq.com</li>
                        <li><i class="fa-solid fa-phone mr-2"></i> 114-514-1919-810</li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-lg font-semibold mb-4">关注我们</h3>
                    <div class="flex space-x-4">
                        <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                            <i class="fa-brands fa-weixin text-xl"></i>
                        </a>
                        <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                            <i class="fa-brands fa-weibo text-xl"></i>
                        </a>
                        <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                            <i class="fa-brands fa-github text-xl"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="border-t border-gray-700 mt-8 pt-8 text-center text-gray-400">
                <p>© 2025 软课程管理平台 版权所有</p>
            </div>
        </div>
    </footer>

    <script type="module" src="js/class-manage.js"></script>
</body>
</html>